﻿using Game2DFramework;
using MechGame.Game.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MechGame.Game.PlayerRobot
{
    class PrimaryWeapon : GameObject
    {
        private readonly Texture2D _weaponTexture;
        private readonly ProjectileManager _projectileManager;
        private readonly Player _player;

        public float ShootFrequency { get; private set; }
        public float ProjectileSpeed { get; private set; }
        public int ProjectilesPerShot { get; private set; }
        public int Damage { get; private set; }
        public float ScatteringAngle { get; private set; }

        public PrimaryWeapon(Player player,
                             float shootFrequency,
                             float projectileSpeed, 
                             int damage = 1,
                             int projectilesPerShot = 1,
                             float scatteringAngle = 0)
            : base(player.Game)
        {
            _projectileManager = Game.GetGlobalObject<ProjectileManager>("ProjectileManager");
            _player = player;
            _weaponTexture = Game.Content.Load<Texture2D>("textures/weapon_laser");
            ShootFrequency = shootFrequency;
            ProjectileSpeed = projectileSpeed;
            ProjectilesPerShot = projectilesPerShot;
            ScatteringAngle = scatteringAngle;
            Damage = damage;
        }

        public void Update()
        {
            if (Game.Mouse.IsLeftMouseDownFreq(ShootFrequency))
            {
                _projectileManager.AddProjectile(_player.Position, ProjectileSpeed, _player.CurrentLookDir, Damage);
            }
        }

        public void Draw()
        {
            Game.SpriteBatch.Draw(_weaponTexture, _player.Position, null, Color.White, _player.HeadRotation, new Vector2(_weaponTexture.Width*0.5f, _weaponTexture.Height * 0.5f), 0.6f, SpriteEffects.None, 0);
        }
    }
}
